//
//  PerfectInfoViewController.m
//  SG
//
//  Created by FISH on 2018/4/20.
//  Copyright © 2018年 yimindai. All rights reserved.
//

#import "PerfectInfoViewController.h"
#import "PopRecomViewController.h"
@interface PerfectInfoViewController ()

@end

@implementation PerfectInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createPerfectInfoViewControllerUI];
}

- (void)createPerfectInfoViewControllerUI
{
    [self createNaViewUI];
    
    [self createIconUI];
    
    [self createMainViewUI];
}

- (void)createNaViewUI
{
    _NaView.frame = CGRectMake(0, 0, kScreenWidth, kNavHeight);
    _contentLab.frame = CGRectMake(40, kNavY+(44-30)/2, kScreenWidth-80, 30);
    _contentLab.font = FONTTHRE;
    _contentLab.text = @"完善资料";
}

- (void)createIconUI
{
    _iconBtn.frame = CGRectMake((kScreenWidth-kRealValue(60))/2, kNavHeight+kRealValue(20), kRealValue(60), kRealValue(60));
    [_iconBtn addTarget:self action:@selector(toTakingPictures) forControlEvents:UIControlEventTouchUpInside];
    JDWeakSelf(self);
    self.block = ^(NSData *image) {
        [weakself.iconBtn setBackgroundImage:[UIImage imageWithData:image] forState:UIControlStateNormal];
    };
    _iconLab.frame = CGRectMake(0, _iconBtn.frame.origin.y+_iconBtn.frame.size.height+10, kScreenWidth, 21);
    _iconLab.font = FONTTWO;
}

- (void)createMainViewUI
{
    _mainView.frame = CGRectMake(0, _iconLab.frame.origin.y+_iconLab.frame.size.height+kRealValue(20), kScreenWidth, kScreenHeight- _iconLab.frame.origin.y-_iconLab.frame.size.height-kRealValue(20));
    _mView1.frame = CGRectMake(20, 0, kScreenWidth-40, 40);
    _mView1.layer.masksToBounds = YES;
    _mView1.layer.cornerRadius = 5;
    _mView1.layer.borderWidth = 1;
    _mView1.layer.borderColor = KLightGrayColor.CGColor;
    _Lab1.frame   = CGRectMake(20, _mView1.frame.origin.y+_mView1.frame.size.height, kScreenWidth-40, 21);
    _mView1Lab.frame = CGRectMake(10, 0, 40, _mView1.frame.size.height);
    _mView1View.frame = CGRectMake(50, 10, 1, 20);
    int TFWIDTH = _mView1.frame.size.width-80-100;
    _mView1Tfield.frame = CGRectMake(60, 0, TFWIDTH, _mView1.frame.size.height);
    _mView1Tfield.text = [self RandomString];
    _mView1Btn.frame = CGRectMake(_mView1.frame.size.width-100, 0, 100, _mView1.frame.size.height);
    [_mView1Btn addTarget:self action:@selector(toRandomString) forControlEvents:UIControlEventTouchUpInside];
    
    _mView2.frame = CGRectMake(20, _mView1.frame.size.height+31, kScreenWidth-40, 40);
    _mView2.layer.masksToBounds = YES;
    _mView2.layer.cornerRadius = 5;
    _mView2.layer.borderWidth = 1;
    _mView2.layer.borderColor = KLightGrayColor.CGColor;
    _Lab2.frame   = CGRectMake(20, _mView2.frame.origin.y+_mView2.frame.size.height, kScreenWidth-40, 21);
    _mView2Lab.frame = CGRectMake(10, 0, 40, _mView1.frame.size.height);
    _mView2View.frame = CGRectMake(50, 10, 1, 20);
    _mView2leftBtn.frame = CGRectMake(80, 0, TFWIDTH/2, _mView1.frame.size.height);
    [_mView2leftBtn addTarget:self action:@selector(toChangeSecureTextEntry:) forControlEvents:UIControlEventTouchUpInside];
    _mView2rightBtn.frame = CGRectMake(80+TFWIDTH/2, 0, TFWIDTH/2, _mView1.frame.size.height);
    [_mView2rightBtn addTarget:self action:@selector(toChangeSecureTextEntry:) forControlEvents:UIControlEventTouchUpInside];

    _mView3.frame = CGRectMake(20, _mView2.frame.origin.y+_mView2.frame.size.height+31, kScreenWidth-40, 40);
    _mView3.layer.masksToBounds = YES;
    _mView3.layer.cornerRadius = 5;
    _mView3.layer.borderWidth = 1;
    _mView3.layer.borderColor = KLightGrayColor.CGColor;
    _mView3Lab.frame = CGRectMake(10, 0, 40, _mView1.frame.size.height);
    _mView3View.frame = CGRectMake(50, 10, 1, 20);
    _mView3Btn.frame = CGRectMake(60, 0, _mView3.frame.size.width-60, _mView1.frame.size.height);
    NSDate *currentdate =[NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *currentDay = [formatter stringFromDate:currentdate];
    [_mView3Btn setTitle:currentDay forState:UIControlStateNormal];
    [_mView3Btn setTitleColor:KBlackColor forState:UIControlStateNormal];
    _mView3Btn.titleLabel.textAlignment = NSTextAlignmentLeft;
    _mView3Btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;// UIButton 文字靠左
    _mView3Btn.titleLabel.font = FONTTWO;
    [_mView3Btn addTarget:self action:@selector(toSelectPicker) forControlEvents:UIControlEventTouchUpInside];
    _loginBtn.frame = CGRectMake(20, _mView3.frame.origin.y+_mView3.frame.size.height+kRealValue(60), kScreenWidth-40, 40);
    [_loginBtn addTarget:self action:@selector(toSelectLogin) forControlEvents:UIControlEventTouchUpInside];
    
#pragma fontSize
    _mView1Lab.font = FONTTWO;
    _mView1Tfield.font = FONTTWO;
    _mView1Btn.titleLabel.font = FONTTWO;
    _Lab1.font = FONTTWO;
    
    _mView2Lab.font = FONTTWO;
    _mView2leftBtn.titleLabel.font = FONTTWO;
    _mView2rightBtn.titleLabel.font = FONTTWO;
    _Lab2.font = FONTTWO;
    
    _mView3Lab.font = FONTTWO;
    _mView3Btn.titleLabel.font = FONTTWO;
}

-(void)toChangeSecureTextEntry:(UIButton*)sender
{
    _bChecked = !_bChecked;
    if (_bChecked == YES)
    {
        _mView2leftBtn.backgroundColor = KBlueColor;
        _mView2rightBtn.backgroundColor =  KClearColor;
    }
    else
    {
        _mView2leftBtn.backgroundColor = KClearColor;
        _mView2rightBtn.backgroundColor =  KRedColor;
    }
}
    
-(void)toSelectPicker
{
    DLog(@"选择时间");
//    [self setupDateView:DateTypeOfStart];
    [self setupDateView:DateTypeOfEnd];

}

-(void)toSelectLogin
{
    DLog(@"开启搜缘");
    PopRecomViewController *PopRecomVC = [[PopRecomViewController alloc]init];
    [self.navigationController pushViewController:PopRecomVC animated:NO];
}

- (void)setupDateView:(DateType)type {
    
    _pikerView = [HZQDatePickerView instanceDatePickerView];
    _pikerView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [_pikerView setBackgroundColor:[UIColor clearColor]];
    _pikerView.delegate = self;
    _pikerView.type = type;
    // 今天开始往后的日期
    //    [_pikerView.datePickerView setMinimumDate:[NSDate date]];
    // 在今天之前的日期
    [_pikerView.datePickerView setMaximumDate:[NSDate date]];
    [self.view addSubview:_pikerView];
    
}

- (void)getSelectDate:(NSString *)date type:(DateType)type {
    switch (type) {
        case DateTypeOfStart:
            [_mView3Btn setTitle:date forState:UIControlStateNormal];
            break;
            
        case DateTypeOfEnd:
            [_mView3Btn setTitle:date forState:UIControlStateNormal];
            break;
        default:
            break;
    }
}

//-(void)TheAssignment:(UIImage*)image
//{
//    NSLog(@"%@",image);
//    [_iconBtn setImage:image forState:UIControlStateNormal];    
//}

- (void)toRandomString
{
    _mView1Tfield.text = [self RandomString];
}

-(NSString*)RandomString
{
    NSString *string = [[NSString alloc]init];
    for (int i = 0; i < 5; i++) {
        int number = arc4random() % 36;
        if (number < 10) {
            int figure = arc4random() % 10;
            NSString *tempString = [NSString stringWithFormat:@"%d", figure];
            string = [string stringByAppendingString:tempString];
        }else {
            int figure = (arc4random() % 26) + 97;
            char character = figure;
            NSString *tempString = [NSString stringWithFormat:@"%c", character];
            string = [string stringByAppendingString:tempString];
        }
    }
    NSLog(@"%@", string);
    return string;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



@end
